package spring.cloud.simple.controller;

import org.apache.thrift.TException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import spring.cloud.simple.interfaces.UserDto;
import spring.cloud.simple.interfaces.UserService;
import spring.cloud.simple.provider.UserServiceProvider;

@Controller
public class UserController {
    @Autowired
    private UserServiceProvider userServiceProvider;

    @ResponseBody
    @RequestMapping(value = "/hello", method = {RequestMethod.GET})
    public String hello() {
        return "Hello Thrift!";
    }

    @ResponseBody
    @RequestMapping(value = "/user", method = {RequestMethod.GET})
    public String getUser() throws TException {
        UserService.Client client = userServiceProvider.getBalanceUserService();
        UserDto userDto = client.getUser();
        return userDto.getUsername();
    }
}